package com.ts.proj.controller;

import com.alibaba.fastjson.JSONArray;
import com.ts.base.controller.BaseController;
import com.ts.common.constant.ConsoleConstant;
import com.ts.proj.entity.*;
import com.ts.proj.service.*;
import com.ts.proj.vo.ErrorDetailAndFile;
import com.ts.proj.vo.ErrorVO;
import com.ts.proj.vo.JijinItemVO;
import com.ts.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ts.common.constant.InsUpdDelFlagConstant;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

//说明 字符串：Test，作为替换字符串

@Controller
public class ProjectController extends BaseController {

    @Autowired
    private SystemColumnService columnService;
    @Autowired
    private SystemFieldService systemFieldService;

    @Autowired
    private SystemConstantService systemConstantService;

    @Autowired
    private CampanyService campanyService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private FileService fileService;

    @Autowired
    private ErrorprojectService errorprojectService;

    @Autowired
    private  ErrorprojectDetailService errorprojectDetailService;

    @Autowired
    private FinanceService financeService;

    @Autowired
    private ProjectMeetingService meetingService;

    @Autowired
    private  InformationService informationService;

    @Autowired
    private ContractService contractService;

    @Autowired
    private SystemUserService systemUserService;

    @Autowired
    private MarketService marketService;

    @Autowired
    private PeopleInfoService peopleInfoService;

    @Autowired
    private JijinItemService jijinItemService;

    @Autowired
    private JijinDetailService jijinDetailService;


    @RequestMapping("/business-pro{router}-list")
    public ModelAndView providerList(@PathVariable("router") String router){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            Object attribute = this.getRequest().getSession().getAttribute(ConsoleConstant.BTNRIGHTS);

            List<PageData> buttonList = (List<PageData>) JSONArray.parse(attribute.toString());
            modelAndView.addObject("buttons", buttonList);

            //先从Redis里面读取-----------------SystemFieldEntity--------attributes freezAttributes-------------------
            PageData pageData = FieldListUtil.fieldsList(columnService, "ProjectEntity", systemFieldService);
            List<PageData> attributes = (List<PageData>) pageData.get("all");

            List<PageData> freezAttributes = (List<PageData>) pageData.get("freeze");
            if(freezAttributes.size()!=0){
                modelAndView.addObject("freeze", pageData.get("freeze"));
            }
            //应该在这里添加列头
            modelAndView.addObject("attributes", attributes);

            modelAndView.addObject("dlg", (List<PageData>) pageData.get("dlg"));



            viewName = "business/project"  + "/pro" + router + "-list";
            SystemUserEntity systemUserEntity = JsonUtils.jsonToObject(this.getRequest().getSession().getAttribute(ConsoleConstant.SESSIONUSER).toString(),SystemUserEntity.class);
            modelAndView.addObject("userId", systemUserEntity.getId());
        }

        modelAndView.setViewName(viewName);
        return modelAndView;
    }


    @RequestMapping("/project-add")
    public ModelAndView adminAddManage() {
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            List<PageData> categoryList = systemConstantService.getConstantValueDesc("proj_category");
            modelAndView.addObject("category", categoryList);
            List<PageData> companyNatureList = systemConstantService.getConstantValueDesc("company_nature");
            modelAndView.addObject("company", companyNatureList);
            modelAndView.addObject("uuid",DateUtil.getID());
            viewName = "business/project/project-add";

        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    /**
     * refreshFlag判断是从哪个页面跳转，是否需要刷新table
     * */
    @RequestMapping("/project-{router}-edit/{id}/{refreshFlag}")
    public ModelAndView projectStateEdit(@PathVariable("id") Integer id,@PathVariable("router") String router,
                                         @PathVariable("refreshFlag") String refreshFlag){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            ProjectEntity byId = projectService.findById(id);
            viewName = "business/project/project-"+router+"-edit";

            if(router.equals("juece")){
                String info = "0";
                if(byId.getProInvestmentMoney()!=null&&!byId.getProInvestmentMoney().equals("")){
                    info = byId.getProInvestmentMoney().toString();
                }
                modelAndView.addObject("paymoney", info);
                PageData constantParamPd = new PageData();
                constantParamPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
                constantParamPd.put("constantKey", "project_invest_type");
                List<SystemConstantEntity> all = systemConstantService.findAll(constantParamPd);
                constantParamPd.put("constantKey", "project_report_type");
                List<SystemConstantEntity> allReport = systemConstantService.findAll(constantParamPd);


                List<PageData> projectInvestTypeList = new ArrayList<>();
                for(SystemConstantEntity entity : all){
                    PageData pd = new PageData();
                    pd.put("key", entity.getConstantValue());
                    pd.put("text", entity.getConstantValueDesc());
                    projectInvestTypeList.add(pd);
                }
                modelAndView.addObject("projectInvestType", projectInvestTypeList);

                List<PageData> projectInvestReportList = new ArrayList<>();
                for(SystemConstantEntity entity : allReport){
                    PageData pd = new PageData();
                    pd.put("key", entity.getConstantValue());
                    pd.put("text", entity.getConstantValueDesc());
                    projectInvestReportList.add(pd);
                }
                modelAndView.addObject("projectInvestReport", projectInvestReportList);
            }

            //投资支付方式格式化
            if(router.equals("touzi")){
                PageData constantPayMethodPd = new PageData();
                constantPayMethodPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
                constantPayMethodPd.put("constantKey", "project_payMethod");
                List<SystemConstantEntity> allPaymethod = systemConstantService.findAll(constantPayMethodPd);
                List<PageData> proPaymentMethod = new ArrayList<>();
                for(SystemConstantEntity entity : allPaymethod){
                    PageData pd = new PageData();
                    pd.put("key", entity.getConstantValue());
                    pd.put("text", entity.getConstantValueDesc());
                    proPaymentMethod.add(pd);
                }
                modelAndView.addObject("proPaymentMethod",proPaymentMethod);
            }

            //将project的proCategory字段改为文字表述
            PageData constantParamPd = new PageData();
            constantParamPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
            constantParamPd.put("constantKey", "proj_category");
            List<SystemConstantEntity> all = systemConstantService.findAll(constantParamPd);
            List<PageData> categoryList = new ArrayList<>();
            for(SystemConstantEntity entity : all){
                if(entity.getConstantValue().equals(byId.getProCategory())) {
                   byId.setProCategory(entity.getConstantValueDesc());
                }
            }

            //将project的state字段改为文字表述
            PageData constantStatePd = new PageData();
            constantParamPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
            constantParamPd.put("constantKey", "proj_state");
            List<SystemConstantEntity> stateAll = systemConstantService.findAll(constantParamPd);
            List<PageData> List = new ArrayList<>();
            for(SystemConstantEntity entity : stateAll){
                if(Integer.valueOf(entity.getConstantValue()) == byId.getProState()) {
                    modelAndView.addObject("proState", entity.getConstantValueDesc());
                }
            }
            modelAndView.addObject("category", categoryList);
            modelAndView.addObject("project", byId);

        }
        modelAndView.addObject("refreshFlag",refreshFlag);
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-ruku-edit/{id}/{refreshFlag}")
    public ModelAndView projectRukuEdit(@PathVariable("id") Integer id,@PathVariable("refreshFlag") String refreshFlag){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            ProjectEntity byId = projectService.findById(id);
            modelAndView.addObject("project", byId);
            viewName = "business/project/project-ruku-edit";
            PageData constantParamPd = new PageData();
            constantParamPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
            //获取项目分类
            constantParamPd.put("constantKey", "proj_category");
            List<SystemConstantEntity> all = systemConstantService.findAll(constantParamPd);
            List<PageData> categoryList = new ArrayList<>();
            for(SystemConstantEntity entity : all){
                PageData pd = new PageData();
                pd.put("key", entity.getConstantValue());
                pd.put("text", entity.getConstantValueDesc());
                categoryList.add(pd);
            }
            modelAndView.addObject("category", categoryList);
            PageData companyPd = new PageData();
            companyPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
//            List<CampanyEntity> companyList = campanyService.findAll(companyPd);
            modelAndView.addObject("nature",systemConstantService.getConstantValueDesc("company_nature"));
            String city = "";
            if(null!=byId.getProProvince()&&!"".equals(byId.getProLocation())&&null!=byId.getProCity()&&!"".equals(byId.getProCity())){
                city = byId.getProProvince() + "/" + byId.getProCity();
            }
            modelAndView.addObject("city", city);
        }
        modelAndView.addObject("refreshFlag",refreshFlag);
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-tuichu-edit/{id}/{refreshFlag}")
    public ModelAndView projectTuichuEdit(@PathVariable("id") Integer id,@PathVariable("refreshFlag") String refreshFlag){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            ProjectEntity byId = projectService.findById(id);
            modelAndView.addObject("project", byId);

            PageData constantParamPd = new PageData();
            constantParamPd.put("deleteFlag", InsUpdDelFlagConstant.DELETE_FLAG_N);
            //获取项目分类
            constantParamPd.put("constantKey", "proj_out_way");
            List<SystemConstantEntity> all = systemConstantService.findAll(constantParamPd);
            List<PageData> outWayList = new ArrayList<>();
            for(SystemConstantEntity entity : all){
                PageData pd = new PageData();
                pd.put("key", entity.getConstantValue());
                pd.put("text", entity.getConstantValueDesc());
                outWayList.add(pd);
            }

            modelAndView.addObject("outWayList", outWayList);
            viewName = "business/project/project-tuichu-edit";
        }
        modelAndView.addObject("refreshFlag",refreshFlag);
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-{stage}-validate/{id}/{state}")
    public ModelAndView projectValidate(@PathVariable("stage") String stage,@PathVariable("id") Integer id,@PathVariable("state") Integer state){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            ProjectEntity byId = projectService.findById(id);
            modelAndView.addObject("entity", byId);
            ProjectEntity projectEntity = projectService.findById(id);
            PageData pd = new PageData();
            pd.put("deleteFlag", "N");
            pd.put("uuid", projectEntity.getUuid());
            List<FileEntity> fileEntities = fileService.findAll(pd);

            PageData temp = new PageData();
            temp.put("deleteFlag", "N");
            temp.put("constantKey", "proj_state");
            temp.put("constantValue", (state+1));
            if(null!=byId.getProJueCeInvestType()&&byId.getProJueCeInvestType().equals("组建基金")&&state==3){
                temp.put("constantValue", 6);
            }
            List<SystemConstantEntity> allDesc = systemConstantService.findAll(temp);

            temp.put("constantKey", "project_upload_name");
            temp.put("constantValue", state);
            List<SystemConstantEntity> all = systemConstantService.findAll(temp);
            List<PageData> uploadFiles = new ArrayList<>();
            for(SystemConstantEntity systemConstantEntity : all){
                PageData result = new PageData();
                List<FileEntity> list = new ArrayList<>();
                for(FileEntity entity : fileEntities){
                    if(systemConstantEntity.getConstantValueDesc().equals(entity.getDocType())){
                        list.add(entity);
                    }
                }
                result.put("name", systemConstantEntity.getConstantValueDesc());
                result.put("size", list.size() + 1);
                result.put("list", list);
                uploadFiles.add(result);
            }
            modelAndView.addObject("nextState", (state + 1));
            if(null!=byId.getProJueCeInvestType()&&byId.getProJueCeInvestType().equals("组建基金")&&state==3){
                modelAndView.addObject("nextState", 6);
            }
            modelAndView.addObject("uploadFiles", uploadFiles);
            String nextStateDesc = "";
            if(1==allDesc.size()){
                nextStateDesc = allDesc.get(0).getConstantValueDesc();

            }
            modelAndView.addObject("nextStateDesc", nextStateDesc);
            viewName = "business/project/project-validate";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/projectInfo-validate/{id}")
    public ModelAndView projectInfoValidate(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){

            ProjectEntity byId = projectService.findById(id);
            modelAndView.addObject("entity", byId);
            ProjectEntity projectEntity = projectService.findById(id);
            //合同管理
            PageData pd = new PageData();
            pd.put("deleteFlag", "N");
            pd.put("proID",id);
            List<ContractEntity> contractEntityList = contractService.findAll(pd);
            modelAndView.addObject("contractEntityList",contractEntityList);

            //财务信息
            PageData financePd = new PageData();
            financePd.put("deleteFlag", "N");
            financePd.put("proID",id);
            List<FinanceEntity> financeEntityList = financeService.findAll(financePd);
            modelAndView.addObject("financeEntityList",financeEntityList);

            //会议
            PageData meetPd = new PageData();
            meetPd.put("deleteFlag", "N");
            meetPd.put("proId",id);
            List<ProjectMeetingEntity> meetingEntityList = meetingService.findAll(meetPd);
            modelAndView.addObject("meetingEntityList",meetingEntityList);

            //重要信息
            PageData infoPd = new PageData();
            infoPd.put("deleteFlag", "N");
            infoPd.put("proID",id);
            List<InformationEntity> informationEntityList = informationService.findAll(infoPd);
            modelAndView.addObject("informationEntityList",informationEntityList);

            viewName = "business/project/projectInfo-validate";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }


    /**
     * 投资编辑页面，点付款方式如果是分期付，点详情进行跳转
     * @param id(projectId)
     * */
    @RequestMapping("/project-payment-detail/{id}")
    public ModelAndView payDetail(@PathVariable Integer id){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("proId",id);
        modelAndView.setViewName("business/finance/payment-detail");
        return modelAndView;

    }

    @RequestMapping("/project-ruku-upload")
    public ModelAndView projectRukuUpload(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            viewName = "business/project/project-ruku-upload";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }



    @RequestMapping("/project-{state}-view/{id}")
    public ModelAndView projectDetail(@PathVariable("state") String state,@PathVariable("id") String id){

        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";

        if(JurisdictionUtil.isValid()){
            String YCflag = "flase";
            ProjectEntity projectEntity = projectService.findById(Integer.valueOf(id));
            ErrorprojectEntity errorprojectEntity = null;
            List<ErrorDetailAndFile> errorDetailAndFileList = new ArrayList<>();
            //如果是异常项目，返回异常详情。
            if(projectEntity.getProState() == -1 || projectEntity.getProState() == 7){
                YCflag = "true";
                PageData pageData = new PageData();
                pageData.put("projectId", Integer.valueOf(id));
                pageData.put("deleteFlag", "N");
                List<ErrorprojectEntity> errorprojectEntityList = errorprojectService.findAll(pageData);
                if(null != errorprojectEntityList && errorprojectEntityList.size() > 0){
                    errorprojectEntity = errorprojectEntityList.get(0);
                }
                modelAndView.addObject("errorprojectEntity",errorprojectEntity);
                PageData pageData1 = new PageData();
                pageData1.put("proID",errorprojectEntity.getId());
                pageData1.put("deleteFlag","N");
                List<ErrorProjectDetailEntity> errorProjectDetailEntityList = errorprojectDetailService.findAll(pageData1);
                for(ErrorProjectDetailEntity entity : errorProjectDetailEntityList){
                    PageData errordetailpd = new PageData();
                    errordetailpd.put("errorDetailId", entity.getId());
                    errordetailpd.put("deleteFlag", "N");
                    List<FileEntity> all = fileService.findAll(errordetailpd);
                    ErrorDetailAndFile errorDetailAndFile = new ErrorDetailAndFile();
                    errorDetailAndFile.setErrorTime(entity.getErrorTime());
                    errorDetailAndFile.setErrorContent(entity.getErrorContent());
                    errorDetailAndFile.setFileEntityList(all);
                    errorDetailAndFileList.add(errorDetailAndFile);
                }
            }
            String uuid = projectEntity.getUuid();
            PageData pd = new PageData();

            pd.put("uuid", uuid);
            pd.put("deleteFlag", "N");

            //根据uuid查询项目中文件
            List<FileEntity> all = fileService.findAll(pd);

            List<FileEntity> ruku = new ArrayList<>();
            List<FileEntity> lixiang = new ArrayList<>();
            List<FileEntity> juece = new ArrayList<>();
            List<FileEntity> touzi = new ArrayList<>();
            List<FileEntity> touhou = new ArrayList<>();
            List<FileEntity> tuichu = new ArrayList<>();
            List<FileEntity> yichang = new ArrayList<>();


            for(FileEntity fileEntity : all){
                if(fileEntity.getState().equals("RK")) {
                    ruku.add(fileEntity);
                }else if(fileEntity.getState().equals("LX")){
                    lixiang.add(fileEntity);
                }else if(fileEntity.getState().equals("JC")){
                    juece.add(fileEntity);
                }else if(fileEntity.getState().equals("TZ")){
                    touzi.add(fileEntity);
                }else if(fileEntity.getState().equals("TH")){
                    touhou.add(fileEntity);
                }else if(fileEntity.getState().equals("TC")){
                    tuichu.add(fileEntity);
                }
            }
            PageData pageData = new PageData();
            pageData.put("deleteFlag",'N');
            pageData.put("proID",projectEntity.getId());
            List<FinanceEntity> financeEntities = financeService.findAll(pageData);
            if(financeEntities != null && financeEntities.size()>0){
                modelAndView.addObject("finance",financeEntities);
            }
            modelAndView.addObject("RKFiles", ruku);
            modelAndView.addObject("LXFiles", lixiang);
            modelAndView.addObject("JCFiles", juece);
            modelAndView.addObject("TZFiles", touzi);
            modelAndView.addObject("THFiles", touhou);
            modelAndView.addObject("TCFiles", tuichu);
         //   modelAndView.addObject("YCFiles", yichang);
            modelAndView.addObject("YCflag",YCflag);
            modelAndView.addObject("errorDetailAndFileList",errorDetailAndFileList);
            modelAndView.addObject("project", projectEntity);
            viewName = "business/project/project-"+state+"-detail";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;

    }


    @RequestMapping( "/query-project-detail/{id}")
    public ModelAndView queryProjectDetail(@PathVariable("id") Integer id){
        ModelAndView modelAndView = new ModelAndView();
        String viewName = "";
        ProjectEntity project = projectService.findById(id);
        //入库
        if(0==project.getProState()){
            SystemUserEntity userEntity = systemUserService.findById(project.getUserId());
            modelAndView.addObject("userName",userEntity.getNickname());
            viewName = "business/project/queryProjectDetail/ruku-detail";
        }

        //立项
        if(1==project.getProState()){
            viewName = "business/project/queryProjectDetail/lixiang-detail";
        }

        //juece
        if(2==project.getProState()){
            viewName = "business/project/queryProjectDetail/juece-detail";
        }

        //touzi
        if(3==project.getProState()){
            viewName = "business/project/queryProjectDetail/touzi-detail";
        }

        //zhitoutouhou /jijin
        if(4==project.getProState() || 6 == project.getProState()){
            PageData financePd = new PageData();
            financePd.put("deleteFlag","N");
            financePd.put("proID",id);
            List<FinanceEntity> financeEntityList = financeService.findAll(financePd);
            List<FinanceEntity> paymentList = new ArrayList<>();
            List<FinanceEntity> incomeList = new ArrayList<>();
            for(FinanceEntity financeEntity: financeEntityList){
                if("0".equals(financeEntity.getMoneyType())){
                    paymentList.add(financeEntity);
                }else if("1".equals(financeEntity.getMoneyType())){
                    incomeList.add(financeEntity);
                }
            }
            modelAndView.addObject("paymentList",paymentList);
            modelAndView.addObject("incomeList",incomeList);

            PageData meetPd = new PageData();
            meetPd.put("deleteFlag","N");
            meetPd.put("proId",id);
            List<ProjectMeetingEntity> meetingEntityList = meetingService.findAll(meetPd);
            modelAndView.addObject("meetingEntityList",meetingEntityList);

            PageData informationPd = new PageData();
            informationPd.put("deleteFlag","N");
            informationPd.put("proID",id);
            List<InformationEntity> informationEntityList = informationService.findAll(informationPd);
            modelAndView.addObject("informationEntityList",informationEntityList);

            PageData contractPd = new PageData();
            contractPd.put("deleteFlag","N");
            contractPd.put("proID",id);
            List<ContractEntity> contractEntityList = contractService.findAll(contractPd);
            modelAndView.addObject("contractEntityList",contractEntityList);

            PageData marketPd = new PageData();
            marketPd.put("deleteFlag","N");
            marketPd.put("proId",id);
            List<MarketEntity> marketEntityList = marketService.findAll(marketPd);
            modelAndView.addObject("marketEntityList",marketEntityList);

            PageData peopleInfoPd = new PageData();
            peopleInfoPd.put("deleteFlag","N");
            peopleInfoPd.put("proID",id);
            List<PeopleInfoEntity> peopleInfoEntityList = peopleInfoService.findAll(peopleInfoPd);
            modelAndView.addObject("peopleInfoEntityList",peopleInfoEntityList);
            if(4 == project.getProState()) {
                viewName = "business/project/queryProjectDetail/zhitoutouhou-detail";
            }else if(6 == project.getProState()){
                PageData jijinPd = new PageData();
                jijinPd.put("deleteFlag","N");
                jijinPd.put("proID",id);
                List<JijinItemEntity> jijinItemEntityList = jijinItemService.findAll(jijinPd);

                List<JijinItemVO> jijinItemVOList = new ArrayList<>();

                for(JijinItemEntity item :jijinItemEntityList ){
                    JijinItemVO jijinItemVO = new JijinItemVO();
                    jijinItemVO.setItemName(item.getItemName());
                    jijinItemVO.setItemTime(item.getItemTime());
                    jijinItemVO.setItemMoney(item.getItemMoney());
                    jijinItemVO.setItemOutTime(item.getItemOutTime());
                    jijinItemVO.setItemOutMoney(item.getItemOutMoney());
                    jijinItemVO.setItemCondition(item.getItemCondition());

                    PageData detailPd = new PageData();
                    detailPd.put("deleteFlag","N");
                    detailPd.put("jijinID",item.getId());
                    List<JijinDetailEntity> detailEntityList = jijinDetailService.findAll(detailPd);
                    jijinItemVO.setJijinDetailEntityList(detailEntityList);
                    jijinItemVOList.add(jijinItemVO);
                }
                modelAndView.addObject("jijinItemVOList",jijinItemVOList);
                viewName = "business/project/queryProjectDetail/jijintouhou-detail";
            }
        }

        //tuichu
        if(5==project.getProState()){
            viewName = "business/project/queryProjectDetail/tuichu-detail";
        }

        //toujue
        if(7==project.getProState() || -1 ==project.getProState()){
            PageData errorPd = new PageData();
            errorPd.put("deleteFlag","N");
            errorPd.put("projectId",id);
            List<ErrorprojectEntity> errorprojectEntityList = errorprojectService.findAll(errorPd);
            ErrorVO errorVO = new ErrorVO();
            ErrorprojectEntity errorprojectEntity = null;
            if(errorprojectEntityList != null && errorprojectEntityList.size()>0){
                errorprojectEntity = errorprojectEntityList.get(0);
                errorVO.setProjectName(errorprojectEntity.getProjectName());
                errorVO.setErrorReason(errorprojectEntity.getErrorReason());
                errorVO.setState(errorprojectEntity.getState());
                errorVO.setVetoFlag(errorprojectEntity.getVetoFlag());
                PageData detailPd = new PageData();
                detailPd.put("deleteFlag","N");
                detailPd.put("proID",errorprojectEntity.getId());
                List<ErrorProjectDetailEntity> errorProjectDetailEntityList = errorprojectDetailService.findAll(detailPd);
                errorVO.setErrorProjectDetailEntityList(errorProjectDetailEntityList);
            }
            modelAndView.addObject("errorVO",errorVO);

            if("ruku".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/ruku-detail";
            }
            if("lixiang".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/lixiang-detail";
            }
            if("juece".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/juece-detail";
            }
            if("touzi".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/touzi-detail";
            }
            if("touhou".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/touhou-detail";
            }
            if("jijintouhou".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/jijintouhou-detail";
            }
            if("tuichu".equals(project.getProLocation())){
                viewName = "business/project/queryProjectDetail/tuichu-detail";
            }

        }



        //格式化
        PageData payMethodPd = new PageData();
        payMethodPd.put("deleteFlag","N");
        payMethodPd.put("constantKey","project_payMethod");
        List<SystemConstantEntity> payMethodConstant = systemConstantService.findAll(payMethodPd);
        for(SystemConstantEntity systemConstantEntity: payMethodConstant){
            if (systemConstantEntity.getConstantValue().equals(project.getProPaymentMethod())){
                modelAndView.addObject("payMethod",systemConstantEntity.getConstantValueDesc());
            }
        }




        //file
        PageData pd = new PageData();
        pd.put("uuid", project.getUuid());
        pd.put("deleteFlag", "N");
        //根据uuid查询项目中文件
        List<FileEntity> all = fileService.findAll(pd);

        List<FileEntity> ruku = new ArrayList<>();
        List<FileEntity> lixiang = new ArrayList<>();
        List<FileEntity> juece = new ArrayList<>();
        List<FileEntity> touzi = new ArrayList<>();
        List<FileEntity> touhou = new ArrayList<>();
        List<FileEntity> tuichu = new ArrayList<>();
        List<FileEntity> yichang = new ArrayList<>();
        List<FileEntity> foujue = new ArrayList<>();

        for(FileEntity fileEntity : all){
            if(fileEntity.getState().equals("RK")) {
                ruku.add(fileEntity);
            }else if(fileEntity.getState().equals("LX")){
                lixiang.add(fileEntity);
            }else if(fileEntity.getState().equals("JC")){
                juece.add(fileEntity);
            }else if(fileEntity.getState().equals("TZ")){
                touzi.add(fileEntity);
            }else if(fileEntity.getState().equals("TH")){
                touhou.add(fileEntity);
            }else if(fileEntity.getState().equals("TC")){
                tuichu.add(fileEntity);
            }else if(fileEntity.getState().equals("YC")){
                yichang.add(fileEntity);
            }else if(fileEntity.getState().equals("FJ")){
                foujue.add(fileEntity);
            }
        }

        modelAndView.addObject("RKFiles", ruku);
        modelAndView.addObject("LXFiles", lixiang);
        modelAndView.addObject("JCFiles", juece);
        modelAndView.addObject("TZFiles", touzi);
        modelAndView.addObject("THFiles", touhou);
        modelAndView.addObject("TCFiles", tuichu);
        modelAndView.addObject("YCFiles", yichang);
        modelAndView.addObject("FJFiles", foujue);

        modelAndView.addObject("project",project);
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

}